<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/home.css" />
    <style>
        .text {
            width: 100%;
            text-align: center;
            margin-top: 25%;
        }

        .text img {
            width: 90px;
            margin: 0 auto;
            display: block;
            vertical-align: middle;
        }
    </style>
</head>

<body>
    <div id="vm">

        <!-- <div class="headerlist" v-if="headerflag">
        </div> -->

        <div class="theme test" v-if="isgetmainvideolist && getmainvideolist.is_show==1" @click="Openjieshao(getmainvideolist)">
            <img v-bind:src="getmainvideolist.img" alt="" class="img">
            <div class="contentt">
                <div style="color:#FF4B21;font-size:16px;">{{getmainvideolist.video_name}}</div>
                <div class="aui-ellipsis-1 introduction" v-html="getmainvideolist.video_introduce_small"></div>
                <div class="aui-clearfix"></div>
            </div>
            <img src="../../image/home/play.png" alt="" class="image">
            <div class="aui-clearfix"></div>
        </div>

        <div class="lists" v-if="!iskong">
            <div class="childlist" @click="Openjieshao(item)" v-for="item in videogetlists">
                <div class="tupian">
                    <!-- <span class="videotype" :class="{videotypedaka:item.video_type==3,videotypemianfei:item.video_type==1}">{{videotype(item.video_type)}}</span> -->
                    <img v-bind:src="item.img" alt="" style="border-radius: 5px;">
                </div>
                <div style="height:66px">
                    <div class="title_set aui-ellipsis-1" v-html="item.video_name"></div>
                    <p class="set aui-ellipsis-1">{{item.video_introduce_small}}</p>
                    <p style="font-size: 13px;  color: #757575;" class="aui-ellipsis-1 test">观看次数：{{item.watch_count}}次</p>
                </div>
            </div>
            <div class="aui-clearfix"></div>
        </div>
        <div class="text" v-else>
            <img src="../../image/home/cat_1.png" alt="">
            <div style="font-size:16px;color:#C8C8C8;margin-top:12px;">暂无内容</div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/rest.js"></script>
<script type="text/javascript" src="../../script/vue.2.5.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/md5.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/paythiry.js"></script>
<script type="text/javascript" src="../../script/faskclick.js"></script>
<script type="text/javascript">
    var uid
    var vm = new Vue({
        el: '#vm',
        data: {
            // headerflag: false,
            videogetlists: [],
            isgetmainvideolist: true,
            getmainvideolist: [],
            page: 1,
            iskong: false
        },
        created: function() {
            var _this = this;
            apiready = function() {
                _this.init();

                api.parseTapmode();
                if ('addEventListener' in document) {
                    document.addEventListener('DOMContentLoaded', function() {
                        FastClick.attach(document.body);
                    }, false);
                }
            }
        },
        methods: {
            init: function() {
                var _this = this;

                _this.leimuid = api.pageParam.leimuid;
                _this.videlist(_this.leimuid)
                    // 主打视频接口
                api.addEventListener({
                    name: 'scrolltobottom',
                    extra: {
                        threshold: 80 //设置距离底部多少距离时触发，默认值为0，数字类型
                    }
                }, function(ret, err) {
                    if (_this.iskong) {
                        _this.page = _this.page
                    } else {
                        api.sendEvent({
                            name: 'gundong',
                        });

                        _this.page = _this.page + 1;
                        _this.videlist(_this.leimuid)
                    }
                });

                // 监听点击切换类目
                api.addEventListener({
                    name: 'changetab'
                }, function(ret, err) {
                    _this.page = 1
                    _this.videogetlists = []
                    _this.leimuid = ret.value.leimuid
                    _this.videlist(ret.value.leimuid)
                });
                api.addEventListener({
                    name: 'loginsuccess'
                }, function(ret, err) {
                    _this.init();
                });
                api.addEventListener({
                    name: 'switchzero'
                }, function(ret, err) {
                  _this.getmainvideo()
                });

                api.setRefreshHeaderInfo({
                    visible: true,
                    loadingImg: 'widget://image/refresh.png',
                    bgColor: '#ccc',
                    textColor: '#fff',
                    textDown: '下拉刷新...',
                    textUp: '松开刷新...',
                    showTime: true
                }, function(ret, err) {
                    _this.page = 1
                    _this.videogetlists = [];
                    api.sendEvent({
                        name: 'xiala',
                    });
                    api.refreshHeaderLoading();
                    _this.getmainvideo()
                    _this.videlist(_this.leimuid);
                });

                _this.getmainvideo()

                api.addEventListener({
                    name: 'yibofang'
                }, function(ret, err) {
                    _this.page = 1
                    _this.videogetlists = []
                    _this.videlist(_this.leimuid)
                });

            },
            getmainvideo() {
                var _this = this;
                new rest().get('getMainVideo').success(function(res) {
                    if (res.flag == 1) {
                        if (res.msg) {
                            _this.getmainvideolist = res.msg
                            _this.isgetmainvideolist = true
                        } else {
                            _this.isgetmainvideolist = false
                        }
                    }
                    console.log(JSON.stringify(res))
                }).error(function(err) {
                    console.log(JSON.stringify(err))
                }).run()
            },

            videotype: function(res) {
                console.log(res);
                if (res == 2) {
                    return 'VIP'
                } else if (res == 3) {
                    return '大咖'
                } else {
                    return '免费'
                }
            },
            Openjieshao: function(item) {
                var _this = this;
                if (uid) {
                    var data1 = {
                        video_id: item.video_id,
                        uid: uid
                    }
                } else {
                    var data1 = {
                        video_id: item.video_id,
                        uid: ''
                    }
                }

                new rest().get('getDetail').datae(data1).success(function(res) {
                    if (res.flag == 1) {
                        apicmmon.openwin('videodetail_win', '../VIP/videodeail.html', {
                            videoid: res.msg.id
                        })
                    } else {
                        api.toast({
                            msg: res.msg,
                            duration: 2000,
                            location: 'middle'
                        });
                    }
                }).error(function(err) {
                    console.log(JSON.stringify(err))
                }).run()

            },
            settime: function(res) {
                return apicmmon.formatDateTime(res)
            },
            videlist: function(leader_id) {
                var _this = this;
                new rest().get('videogetlist').datae({
                    leader_id: leader_id,
                    page: _this.page
                }).success(function(res) {
                    console.log(JSON.stringify(res))
                    if (res.msg.length == 0) {
                        if (_this.page == 1) {
                            _this.iskong = true;
                            api.refreshHeaderLoadDone(); // 移除这个效果
                        } else {
                            _this.iskong = false;
                            _this.page = _this.page;
                            api.toast({
                                msg: '没有更多了',
                                duration: 2000,
                                location: 'middle'
                            });
                        }
                    } else {
                        _this.iskong = false;
                        _this.videogetlists = _this.videogetlists.concat(res.msg);
                        var shangxian = res.msg.length;
                        var num;
                        if (shangxian != 1) {
                            num = Math.floor(Math.random() * (shangxian - 1) + 1)
                        } else {
                            num = 0
                        }
                        $api.setStorage('homevideoid', res.msg[num].video_id);
                        $api.setStorage('homevideoname', res.msg[num].video_name);
                        api.refreshHeaderLoadDone(); // 移除这个效果
                    }
                }).run()
            },
        }
    })
</script>

</html>
